<?php
/**
 * Created by PhpStorm.
 * User: manarch
 * Date: 2017/11/15
 * Time: 22:51
 */

namespace App\Widget;

use Menu;
use Auth;
class SideBar
{
    public function __construct()
    {
        Menu::make('MenuList',function($menu){

            $homeBar = $menu->add('首页',['url'=>route('index')])->prepend('<i class="fa fa-home"></i>')->data(['permissions'=>['show-home']]);

            $UserBar = $menu->add('用户管理',['class'=>'treeview'])->prepend('<i class="fa fa-users"></i>')->append('<span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span>')->data(['permissions'=>['manager-user']]);
            $articleBar = $UserBar->add('用户列表',['url'=>route('user.index')])->prepend('<i class="fa fa-circle-o"></i>')->data(['permissions'=>['show-users']]);
            $roleBar = $UserBar->add('角色列表',['url'=>route('role.index')])->prepend('<i class="fa fa-circle-o"></i>')->data(['permissions'=>['show-roles']]);
            $permissionBar = $UserBar->add('权限列表',['url'=>route('permission.index')])->prepend('<i class="fa fa-circle-o"></i>')->data(['permissions'=>['show-permissions']]);
        })->filter(function($item){
            if(Auth::user()->hasRole('SuperManager') || Auth::user()->can($item->data('permissions'))){
                return true;
            }
            return false;
        });
    }
}